package com.lace.service.web.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.plugins.pagination.PageHelper;
import com.lace.common.entity.TbCompanyInfo;
import com.lace.service.web.service.TbCompanyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mybatis-plus generator codes
 * @since 2018-07-15
 */
@Controller
@RequestMapping("/v1/tbCompanyInfos")
public class TbCompanyInfoController {

    @Autowired
    private TbCompanyInfoService tbCompanyInfoService;


    @GetMapping
    @ResponseBody
    public Object selectAll(){
        return  tbCompanyInfoService.selectList(null);
    }


    @GetMapping("page")
    @ResponseBody
    public Object selectByWrapper(Page page,String name){
        return  tbCompanyInfoService.selectPage(page,new EntityWrapper<TbCompanyInfo>().like("company_name","%"+name+"%"));
    }

    @GetMapping("bysql")
    @ResponseBody
    public Object selectBySql(){
        return tbCompanyInfoService.selectListBySQL();
    }

    @GetMapping("pagebysql")
    @ResponseBody
    public Object selectPageBySql(Page page){
        PageHelper.setPagination(page);
        page.setRecords(tbCompanyInfoService.selectListPageBySQL(page));
        page.setTotal(PageHelper.freeTotal());
        return page;
    }

    @GetMapping("{id}")
    @ResponseBody
    public Object findOne(@PathVariable Long id){
        return  tbCompanyInfoService.selectById(id);
    }

    @PostMapping
    @ResponseBody
    public Object insert(@RequestBody TbCompanyInfo tbCompanyInfo){
        tbCompanyInfoService.insert(tbCompanyInfo);
        return tbCompanyInfo;
    }

    @DeleteMapping("{id}")
    @ResponseBody
    public Object deleteOne(@PathVariable Long id){
        tbCompanyInfoService.deleteById(id);
        return "success";
    }

    @GetMapping("test")
    @ResponseBody
    public Object test(){
        TbCompanyInfo tbCompanyInfo = new TbCompanyInfo();
        tbCompanyInfo.setAddress("Sdadsfas");
        tbCompanyInfo.setCity("fujian");
        return tbCompanyInfo;
    }

}

